package main

import (
	_ "beego-restful-server/routers"
	"github.com/astaxie/beego"
	"beego-restful-server/com"
	"gopkg.in/mgo.v2/bson"
	"github.com/bugfan/logrus"
)
type dog struct{
	Id bson.ObjectId "_id"
	Name string
	Email string
}
func init(){
	// 初始化关系型数据库
	com.InitOrm(
		com.Conf.GetString("db_user"),
		com.Conf.GetString("db_pwd"),
		com.Conf.GetString("db_port"),
		com.Conf.GetString("db_name"),
		com.Conf.GetString("db_num"),
		com.Conf.GetString("db_host"),
	)
	// 初始化rdis会话
	com.InitRedis("redis://reids:0129@localhost:6379/11")
	com.Redis.Do("set","zxy","zxy")
	com.Redis.Close()
	// 初始化mongodb
	com.InitMongodb("localhost:27017")
	c:=com.MongoDB.DB("animal").C("dog")		//打开animal数据库 dog集合（表）
	c.Insert(&dog{
		Id:bson.NewObjectId(),
		Name:"zxy",
		Email:"xxx@qq.com",
	})
	c.Insert(&map[string]string{
		"mkey":"mvalue",
	})	
	com.MongoDB.Close()
	logrus.Info("--初始化完成--")
}
func main() {
	beego.Run(":8090")
}

